package com.zzyl.controller.security;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.UserDto;
import com.zzyl.entity.User;
import com.zzyl.service.UserService;
import com.zzyl.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(path = "/user")
@RequiredArgsConstructor
@Api(tags = "用户管理")
public class UserController {
    private final UserService userService;

    @PostMapping(path = "/page/{pageNum}/{pageSize}")
    @ApiOperation("用户分页")
    public ResponseResult<PageResponse<UserVo>> pageQuery(@PathVariable Integer pageNum,@PathVariable Integer pageSize, @RequestBody UserDto userDto){
        PageResponse<UserVo> pageQuery = userService.pageQuery(pageNum,pageSize,userDto);
        return ResponseResult.success(pageQuery);
    }

    @PutMapping
    @ApiOperation("用户添加")
    public ResponseResult<Void> addUser(@RequestBody UserDto userDto){
        userService.addUser(userDto);
        return ResponseResult.success();
    }

    @PatchMapping
    @ApiOperation("用户修改")
    public ResponseResult<Void> modifyUser(@RequestBody UserDto userDto){
        userService.modifyUser(userDto);
        return ResponseResult.success();
    }

    @PutMapping(path = "/is-enable/{id}/{status}")
    @ApiOperation("启用/禁用")
    public ResponseResult<Void> modifyUserStatus(@PathVariable String id,@PathVariable String status){
        userService.modifyUserStatus(id,status);
        return ResponseResult.success();
    }

    @DeleteMapping(path = "/remove/{userIds}")
    @ApiOperation("删除用户")
    public ResponseResult<Void> deleteUser(@PathVariable String userIds){
        userService.deleteUser(userIds);
        return ResponseResult.success();
    }

    @PostMapping(path = "/reset-passwords/{userId}")
    @ApiOperation("删除用户")
    public ResponseResult<Void> resetPassword(@PathVariable String userId){
        userService.resetPassword(userId);
        return ResponseResult.success();
    }

    @PostMapping(path = "/list")
    @ApiOperation("用户列表")
    public ResponseResult<User> userList(@RequestBody String realName){
        User user = userService.userList(realName);
        return ResponseResult.success(user);
    }

}
